package com.rd.teacher.jichao.day11;

import java.util.Scanner;

// 金字塔
public class Pyramid {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入金字塔层数：");
        // 层数
        int layer = scanner.nextInt();
        info2(layer);

    }

    public static void info(int layer) {
        // 需要两种符号的打印  分别是 空格 和 *
        // 可以计算最后一层的星星个数
        // 0 1 -> 1
        // 1 2 -> 3
        // 2 3 -> 5
        //  ...
        // 5 6 -> 11

        int lastLayer = layer * 2 - 1;
        // 创建一个循环结构来逐层打印
        // 计算每一层的空格数量和星号数量
//        for (int i = 1; i <= layer; i++) {
        for (int i = 0; i < layer; i++) {
            // 如果层数是从0开始计算  当前层的星号个数是 2 * i +1
            int currentLayer = i * 2 + 1;
            // 计算当前层的空格个数
            // 1   11 - 1  10/2  5
            // 2   11 - 3   8/2  4
            int blankNum = (lastLayer - currentLayer) / 2;
            for (int j = 0; j < blankNum; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j < currentLayer; j++) {
                System.out.print("*");
            }

            System.out.println();
        }
    }

    public static void info1(int layer) {
        StringBuilder builder = new StringBuilder();
        int lastLayer = layer * 2 - 1;
        for (int i = 0; i < layer; i++) {
            int currentLayer = i * 2 + 1;
            int blankNum = (lastLayer - currentLayer) / 2;
            for (int j = 0; j < blankNum; j++) {
                builder.append(" ");
            }
            for (int j = 0; j < currentLayer; j++) {
                builder.append("*");
            }
            builder.append("\n");
        }
        System.out.println(builder);
    }

    public static void info2(int layer) {
        int lastLayer = layer * 2 - 1;
        String[][] arr = new String[layer][lastLayer];
        for (int i = 0; i < layer; i++) {
            int currentLayer = i * 2 + 1;
            int blankNum = (lastLayer - currentLayer) / 2;
            for (int j = 0; j < currentLayer; j++) {
                arr[i][blankNum] = "*";
                blankNum++;
            }
        }

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
               if(arr[i][j] == null){
                   System.out.print(" ");
               }else{
                   System.out.print(arr[i][j]);
               }
            }
            System.out.println();
        }

    }

}
